<%--                                                                       --%>
<%-- Copyright (c) 2001-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>

<%@ page import="java.util.List" %>
<%@ page import = "java.util.HashMap" %>
<%@ page import = "org.apache.struts.util.RequestUtils" %>
<%@ page import="com.broadvision.portal.services.microsite.Microsite" %>
<%@ page import="com.broadvision.portal.services.microsite.Template" %>
<%@ page import="com.broadvision.portal.services.PortalVisitor" %>
<%@ page import="com.broadvision.web.servlet.SessionVisitor" %>

<%
PortalVisitor visitor = null;
int serviceId = 0;
long visitorId  = 0;

// Get the Portal Visitor:
try {
  visitor =  SessionVisitor.getInstance(request.getSession()).getPortalVisitor();
  serviceId = visitor.getContext().getServiceId();
  visitorId = visitor.getId();
}
catch(Exception e) {
  %>
  <bean:message key="cs.index.visitor.error"/>
  <%
}

//Get the template ID for Projects:
List templates = Template.getTemplates(serviceId, visitor);
Template template = null;
long projectTemplId = -1;
long communityTemplId = -1;
String projScriptPath = "";
String commScriptPath = "";

for (int i = 0; i < templates.size(); i++) {
	template = (Template) templates.get(i);
	if ((template.getName()).equals("Projects")) {
		projectTemplId = template.getId();
		//projScriptPath = template.getScriptPath();
		// returns /cs/micrositeHome.do but need it to be /cs/defaultMicrositeHome.do
		projScriptPath = "/cs/defaultMicrositeHome.do";
		
	}
	if (template.getName().equals("Communities")) {
		communityTemplId = template.getId();
		//commScriptPath = template.getScriptPath();
		// returns /cs/micrositeHome.do but need it to be /cs/defaultMicrositeHome.do
		commScriptPath = "/cs/defaultMicrositeHome.do";
	}
}
	
// Get the microsites for projects:
List projList=null;
if( projectTemplId != -1 ) {
	try {
		 projList= Microsite.getMicrositesForTemplate(serviceId, projectTemplId,visitor);
	}  
	catch (Exception e) {
	  %>
		  <bean:message key="cs.index.error"/>
	  <%
	}
}


// Get the microsites for communities:
List commList=null;
if( communityTemplId != -1 ) {
	try {
		 commList= Microsite.getMicrositesForTemplate(serviceId, communityTemplId,visitor);
	}  
	catch (Exception e) {
	  %>
		  <bean:message key="cs.index.error"/>
	  <%
	}
}


%>


<form name="projectIndexForm" action="/cs/micrositeIndex.do" method="post">

  <table width="100%" border="0" cellspacing="0" cellpadding="10">
    <tr>
      <td><h2><bean:message key="cs.index.project.list"/></h2></td>
    <tr>
    <%
    for( int i=0; i<projList.size() ; i++ ) {
    Microsite microsite = (Microsite)(projList.get(i));
    String micName = microsite.getName();
 
    HashMap params = new HashMap();
    params.put("micrositeId", Long.toString(microsite.getId()));
    params.put("currentPhaseId", Long.toString(-1));
    params.put("currentAction", "home");
    String nextAction = projScriptPath;
    String nextPage = RequestUtils.computeURL(pageContext,
                                              null,
                                              null,
                                              nextAction,
                                              params,
                                              null,
                                              false);
   
  
    %>
    <tr>
      <td>
        <a href="<%=nextPage%>"><%= micName%></a>
      </td>
      
      <!-- <td><%= micName %> </td> -->
    </tr>
    <%
    }
    %>
  </table>
  
  <table width="100%" border="0" cellspacing="0" cellpadding="10">
     <tr>
       <td><h2><bean:message key="cs.index.communities.list"/></h2></td>
     <tr>
     <%
     for( int i=0; i<projList.size() ; i++ ) {
     Microsite microsite = (Microsite)(commList.get(i));
     String micName = microsite.getName();
  
     HashMap params = new HashMap();
     params.put("micrositeId", Long.toString(microsite.getId()));
     params.put("currentPhaseId", Long.toString(-1));
     params.put("currentAction", "home");
     String nextAction = projScriptPath;
     String nextPage = RequestUtils.computeURL(pageContext,
                                               null,
                                               null,
                                               nextAction,
                                               params,
                                               null,
                                               false);
    
   
     %>
     <tr>
       <td>
         <a href="<%=nextPage%>"><%= micName%></a>
       </td>
       
       <!-- <td><%= micName %> </td> -->
     </tr>
     <%
     }
     %>
   </table>
   
 
     
</form>
